#include <iostream>
#include <sstream>
#include <string>

#include <server/gfs.h>
#include <server/CmdStructs.h>

using namespace std;

int main(int argc,char ** argv)
{
    if(argc < 2){
        cout<<argv[0]<<" [FILE]\n";
        return 1;
    }
    __ReadStream rds(argv[1]);
    if(!rds.IsOpened()){
        cout<<"cannot open file "<<argv[1]<<endl;
        return 1;
    }
    while(!!rds){
        //CLogKey key;
        //CLogValue value;
        //rds>>key>>value;
        CLogRecord record;
        rds>>record;
        if(rds.GetStatus() == ERR_DATA_END){
            cout<<"end of file\n";
        }else if(!rds){
            cout<<"read log from logfile='"<<argv[1]<<"' error, "<<CFile::ErrMsg()
                <<", record="<<record.ToString();
        }else{
            cout<<"record="<<record.ToString()<<endl
                <<endl;
        }
    }
}
